<template>
  <div>
    <div class="tree-box">
      <el-tree :data="tableData" :props="defaultProps" node-key="primaryKey" default-expand-all class="tree-line">
        <span class="custom-tree-node" slot-scope="{ data }" @click.stop="handleView(data)">
          <span :class="data.bizType == 'enterprise' ? 'font-weight-700' : ''" class="font-size-16">{{ data.planYear }}年{{ data.planMonth ? data.planMonth + '月' : '' }}{{ data.bizName }}</span>
          <span class="font-size-16">（{{ data.planType == 0 ? '年度计划' : data.planType == 1 ? '编制计划' : '执行计划' }}）</span>
        </span>
      </el-tree>
    </div>
  </div>
</template>
<script>
  import { getMenuList } from '@/api';

  export default {
    props: {
      tableData: {
        type: Array,
        default: () => {
          return {};
        },
      },
    },
    data() {
      return {
        statusList: ['', '执行中', '审批中', '', '草稿'],
        defaultProps: {
          children: 'planInfoList',
          label: 'bizName',
        },
      };
    },
    methods: {
      async handleView(item) {
        item.planKey = item.primaryKey;
        if (item.bizType == 'enterprise') {
          item.planKey = item.planInfoList && item.planInfoList.length > 0 ? item.planInfoList[0].primaryKey : '';
        }
        this.goInfo(item);
      },

      async goInfo(item) {
        let pathName = '';
        let planName = '';
        if (item.planType == 0) {
          planName = item.planYear + '财年集团计划';
        } else if (item.planType == 1) {
          planName = item.planYear + '财年' + item.bizName + '项目计划';
        } else if (item.planType == 2) {
          planName = item.bizName + '项目月度执行情况';
        }
        let queryData = {
          planKey: item.planKey || '',
          projectKey: item.projectKey || '',
          headerName: planName,
          year: item.planYear || '',
          month: item.planMonth || '',
        };
        if (item.planType == 0) {
          pathName = 'year-all-plan'; //年度
        } else if (item.planType == 1) {
          pathName = 'compile-all-plan'; //编制
        } else if (item.planType == 2) {
          pathName = 'execute-all-plan'; //执行
        }

        let pathUrl = {
          name: pathName,
          query: queryData,
        };

        let { href } = this.$router.resolve(pathUrl);
        window.open(href);
      },

      // async handleView(item) {
      //   item.planKey = item.primaryKey
      //   if (item.bizType == 'enterprise') {
      //     item.planType = '1'
      //     item.planKey = item.planInfoList && item.planInfoList.length > 0 ? item.planInfoList[0].primaryKey : ''
      //   }
      //   this.goInfo(item);
      // },

      // async goInfo(item) {
      //   let res = await getMenuList({
      //     parentId: this.$route.query.menuId,
      //     likeDescription: item.planType == 1 ? '0' : '1',
      //   });
      //   // let year = item.planYear.substring(0, 4);
      //   let menuUrl = res.rows[0].menuUrl;
      //   let separator = menuUrl.indexOf('?') > -1 ? '&' : '?';
      //   let planType = item.planType == 1 ? '年度计划' : '执行计划';
      //   let planMonth = item.planMonth ? '年' + item.planMonth + '月' : '';
      //   let planName = item.planYear + planMonth + planType;
      //   let queryData = {
      //     isRefresh: true,
      //     parentMenuId: this.$route.query.menuId,
      //     menuId: res.rows[0].primaryKey,
      //     type: item.planType == 1 ? '1' : '2',
      //     likeDescription: item.planType == 1 ? '0' : '1',
      //     planKey: item.planKey,
      //     projectKey: item.projectKey,
      //     headerName: planName,
      //     token: localStorage.getItem("token")
      //   };

      //   let paramData = [];
      //   for (let key in queryData) {
      //     paramData.push(key + '=' + queryData[key]);
      //   }
      //   let href = menuUrl + separator + paramData.join('&');
      //   this.openUrl(href,item)
      // },

      openUrl(href, item) {
        let origin = '';
        if (location.hostname == 'commercial-rent.block-os.com') {
          origin = 'pms.block-os.com';
        } else if (location.hostname == 'pam.jh-sg.com') {
          origin = 'opm.jh-sg.com';
        }
        let path = href;
        if (item.bizType != 'enterprise') {
          path = origin ? 'https://' + origin + href : href;
        }
        window.open(path);
      },
    },
  };
</script>
<style lang="scss" scoped="">
  ::v-deep .tree-line .el-tree-node__expand-icon.is-leaf {
    color: inherit;

    &::before {
      content: '●';
      font-size: 12px;
      line-height: 22px;
      color: #000;
      opacity: 0.8;
    }
  }
</style>
